package com.engr.springbooteasypoi.thread;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * @author : liuYanXin
 * @Description :
 * @Date : 2020-03-31
 */
public class CyclicBarrierCls {

    private static CyclicBarrier barrier;

    static class Thread1 extends Thread {

        @Override
        public void run() {
            System.out.println(Thread.currentThread().getName() + "达到...");
            try {
                barrier.await();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (BrokenBarrierException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "执行完成...");
        }


    }

    public static void main(String[] args) {
        barrier = new CyclicBarrier(5);
        for (int i = 1; i <= 5; i++) {
            new Thread1().start();
        }
    }
}
